package com.wcl.demo.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import com.wcl.demo.application.BaseApplication;

/**
 * Created by dllo on 15/12/8.
 */
public class PreferenceManager {
    private static SharedPreferences mSharedPreferences;
    private static PreferenceManager mPreferencemManager;
    private static SharedPreferences.Editor editor;

    /**
     * 单例模式，获取instance实例
     *
     * @param cxt
     * @return
     */
    public synchronized static PreferenceManager getInstance() {
        if (mPreferencemManager == null) {
            mPreferencemManager = new PreferenceManager(BaseApplication.getContext());
        }
        return mPreferencemManager;
    }


    private PreferenceManager(Context cxt) {
        mSharedPreferences = cxt.getSharedPreferences("USERINFOR", Context.MODE_PRIVATE);
        editor = mSharedPreferences.edit();
    }

    public void setCurrentUserNick(String nick) {
        editor.putString("USERNICKNAME", nick);
        editor.commit();
    }

    public void setCurrentUserAvatar(String avatar) {
        editor.putString("USERHEADIMAGE", avatar);
        Log.i("lllllll" , avatar);
        editor.commit();
    }

    public String getCurrentUserNick() {
        return mSharedPreferences.getString("USERNICKNAME", null);
    }

    public String getCurrentUserAvatar() {
        return mSharedPreferences.getString("USERHEADIMAGE", null);
    }

    public void setCurrentUserName(String username) {
        editor.putString("CURRENTUSERNAME", username);
        editor.commit();
    }

    public String getCurrentUsername() {
        return mSharedPreferences.getString("CURRENTUSERNAME", null);
    }
}
